package com.hnnu.shoppingtoghter.demo.config;

import com.hnnu.shoppingtoghter.demo.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/*** @Description: 注册拦截器
 * @Author: PDY
 * @CreateTime： 2022/7/3 15:14 
 */
@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Value("${shopping.toghter.interceptor.exclude.path.patterns}")
    private String[] EXCLUDE_PATH_PATTERNS;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());
        // /** 代表所有路径，举例：/a, /a/b
        // /user/* 只拦截 /user/b  /user    不拦截 /user/a/b
        registration.addPathPatterns("/**");
       //设置拦截白名单，这些请求不在拦截范围内
       //每个白名单地址作为单个字符串传入excludePathPatterns函数中
       /*registration.excludePathPatterns("/login", "/css/**", "/calendar/**", "/images/**", "/js/**", "/public/**,/api/**",
               "/register", "/css/**", "/calendar/**","/index/**","/mall_list/*");*/
        registration.excludePathPatterns(EXCLUDE_PATH_PATTERNS);
    }
}
